<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子32-JS进阶（二）</title>
    </head>

    <body>
        <pre>
            <code>
                    // 例子32

                    function Person(name, age){
                        this.name = name;
                        this.age = age;
                    }

                    Person.prototype.getName = function() {
                            return this.name;
                    }

                    function Student(name, age, grade, _class) {
                            Person.call(this, name, age); //构造函数继承
                            this.grade = grade;
                            this.class = _class;
                    }

                    Student.prototype = new Person(); // 原型继承
                    Student.prototype.constructor = Student; // 这句不能漏掉了
                    Student.prototype.getGradeAndClass = function() {
                            return 'Grade ' + this.grade + ' Class ' + this.class;
                    }

                    var Tom = new Student('Tom', 10, 2, 5);
                    Tom.getName(); // "Tom"
                    Tom.getGradeAndClass(); // "Grade 2 Class 5"
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/32.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>

</html>